﻿
Imports osi.root.lock
Imports osi.root.delegates

Namespace application_lifetime
    Public Module _application_lifetime
        Private f As singleentry

        Public Function running() As Boolean
            Return f.not_in_use()
        End Function

        Public Function stopping() As Boolean
            Return f.in_use()
        End Function

        Public Sub stopping_handle(ByVal v As void)
            application_lifetime_binder.instance.insert(New auto_disposer(Of Byte)(Function() 0,
                                                                                   disposer:=Sub(ByRef i) v()))
        End Sub

        Sub New()
            assert(Not f.in_use())
            stopping_handle(Sub() f.mark_in_use())
        End Sub
    End Module
End Namespace
